package org.peipito.prs;

import org.peipito.prs.engine.GameEngine;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.util.Log;
import android.view.SurfaceView;

public class Result {

	private static final String TAG = Result.class.getSimpleName();
	
	/**
	 * VICTORY, LOST or DRAW bitmap
	 */
	private Bitmap [] bitmapResult;
	private Bitmap [] bitmapResultClicked;
	
	private GameEngine gameEngine;
	
	public Result(Bitmap [] bitmapResult,
			Bitmap [] bitmapResultClicked) {
		this.bitmapResult = bitmapResult;
		this.bitmapResultClicked = bitmapResultClicked;
	}
	
	public void update(long gameTime){
		
	}
	
	public boolean drawResultClicked = false;

	private long previousTime = 0l;
	
	public void draw(Canvas canvas,SurfaceView surfaceView) {
		if(GameEngine.gamePhase == GameEngine.RESULT){
			if(!drawResultClicked){
				canvas.drawBitmap(bitmapResult[gameEngine.getResult()],0,300,null);
			}
			else{
				canvas.drawBitmap(bitmapResultClicked[gameEngine.getResult()],0,300,null);
				
				if(previousTime==0){
					previousTime = System.currentTimeMillis();
				}else if ( System.currentTimeMillis() - previousTime > 1000){
					((MainGamePanel)surfaceView).init();
				}
			}
		}
	}
	
	public void handleActionDown(int x, int y,SurfaceView surfaceView) {
		if(GameEngine.gamePhase == GameEngine.RESULT){
			drawResultClicked = true;
		}
	}
	
	public void setEngine(GameEngine gameEngine){
		this.gameEngine = gameEngine;
	}
	
	public void init(){
		drawResultClicked 	= false;
		previousTime 		= 0l;
	}
	
}
